package llm

import (
	"context"
	"sync"

	"paper-pro/app/assistant/api/internal/svc"
	"paper-pro/app/assistant/api/internal/types"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/logx"
)

var loadLlmJsonOnce sync.Once
var llmJson *types.LlmJsonResp

type ListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// list assistant support llm
func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListLogic) List() (resp *types.LlmJsonResp, err error) {
	// todo: 后续可考虑用etcd做分发或直接存到数据库里用redis做缓存
	loadLlmJsonOnce.Do(func() {
		llmJson = &types.LlmJsonResp{}
		conf.MustLoad(l.svcCtx.Config.LlmJsonPath, llmJson)
	})

	return llmJson, nil
}
